package mypetstore.web.servlet;

import mypetstore.domain.Item;
import mypetstore.domain.Product;
import mypetstore.service.CatalogService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class ItemFormServlet extends HttpServlet
{
    private CatalogService catalogService;
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        String itemId = request.getParameter("itemId");
        catalogService=new CatalogService();
        Item item=catalogService.getItem(itemId);
        Product product=item.getProduct();

        HttpSession session=request.getSession();
        session.setAttribute("product",product);
        session.setAttribute("item",item);
        request.getRequestDispatcher("/WEB-INF/jsp/catalog/item.jsp").forward(request,response);
    }
}
